﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Common;
using QxFramework.Core;
using System;
public class Explosion : SceneMonoBase
{
    public int BuffNum = 2;
    public override void Awake()
    {
        base.Awake();
    }
    public override void OnEnable()
    {
        base.OnEnable();
        StartCoroutine(Init());
    }
    IEnumerator Init()
    {
        yield return 0;
        CheckPlayerIsIn();
        GameObject clone = ResourceManager.Instance.Instantiate("Prefabs/Effects/Explosion_" + GameMgr.Get<IMonoManager>().CurrentAttrName(sceneMonoData.attr));
        clone.transform.position = transform.position;
        yield return 0;
        GameMgr.Get<ISceneMonoManager>().RemoveSceneMono(gameObject.name);
    }
    public override void Update()
    {
        base.Update();
    }

    private void CheckPlayerIsIn()
    {
        foreach (GameObject obj in GameMgr.Get<IMonoManager>().GetAllMono()._ObjList.Values)
        {
            if ((GameMgr.Get<IMonoManager>().GetMono(obj.name).Position - sceneMonoData.position).magnitude < GetComponent<CircleCollider2D>().radius)
            {
                AddBuff(obj);
                PushOthers(obj, (GameMgr.Get<IMonoManager>().GetMono(obj.name).Position - sceneMonoData.position).normalized,0.1f,8);
            }
        }
    }
    private void PushOthers(GameObject obj,Vector3 Direct,float Speed,int Frame)
    {
        obj.GetComponent<MonoBase>().LastTimeMove(Direct, Speed, Frame, () => { });
    }
    private void AddBuff(GameObject obj)
    {
        int buffID = 0;
        switch (sceneMonoData.attr)
        {
            case MonoAttribute.None:
                buffID = 0;
                break;
            case MonoAttribute.Fire:
                buffID = 1;
                break;
            case MonoAttribute.Ice:
                buffID = 2;
                break;
            case MonoAttribute.Shine:
                buffID = 3;
                break;
            case MonoAttribute.Dark:
                buffID = 4;
                break;
            case MonoAttribute.Steam:
                buffID = 5;
                break;
            case MonoAttribute.Electric:
                buffID = 6;
                break;
            case MonoAttribute.Oil:
                buffID = 7;
                break;
            default:
                break;
        }
        GameMgr.Get<IBuffManager>().AddBuff(GameMgr.Get<IMonoManager>().GetMono(obj.name), buffID, BuffNum);
    }
}
